import org.junit.Test;

import java.io.*;

/**
 * @Author talent_dog
 * @Date 2024/1/16 11:50
 * @Version 1.0
 */
public class HomeWork01 {
    //在判断e盘下是否有文件夹mytemp,如果没有就创建mytemp
    @Test
    public void work01() throws IOException {
        File file = new File("C:\\Users\\23652\\Desktop\\bs\\test\\mytemp\\");
        if (file.exists()){
            System.out.println("存在");
        }else {
            file.mkdir();
        }
    }
    //在e:\\mytemp 目录下,创建文件 hello.txt
    @Test
    public void work02() throws IOException {
        File file = new File("C:\\Users\\23652\\Desktop\\bs\\test\\mytemp\\hello.txt");
        if (file.exists()){
            System.out.println("存在");
        }else {
            file.createNewFile();
        }
    }
    //如果hello.txt 已经存在，提示该文件已经存在，就不要再重复创建了,并写入hello，world
    @Test
    public void work03() throws IOException {
        File file = new File("C:\\Users\\23652\\Desktop\\bs\\test\\mytemp\\hello.txt");
        if (file.exists()){
            System.out.println("已经存在");
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
            bufferedWriter.write("hello,world");
            bufferedWriter.close();
        }else {
            System.out.println("不存在");
        }
    }
}
